New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use %w instead of %v to format errors #99389
Conversation
@tanjing2020: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Hi @tanjing2020. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/release-note-none |
@tanjing2020: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the commit subject need to be updated, iiuc, this is not wrapping anything, and most of case "%w" is identical to "%v" but seems the "%w" is better under some situation.
9fcd2fc
to
902ee8f
Compare
/recc @chendave |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%w
is never better than %v
, and the difference is that whether we want to expose the underlying errors to callers. So please check one by one instead of search and replace all.
Why so? There are certain scenarios where we need to compare underlying errors. Just migrating everything to wrapped errors keeps consistency, so that we are ready to check errors when needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep this PR focused, limit the changes to pkg/scheduler/framework, as those are the errors we are more likely to care about being wrapped.
aha, what I want to say is |
I don't think picking is worth the effort, given that the downsides of migrating everything are negligible. |
902ee8f
to
6ca9bc4
Compare
@@ -108,14 +108,14 @@ func (pl *ServiceAffinity) createPreFilterState(pod *v1.Pod) (*preFilterState, e | |||
// Store services which match the pod. | |||
matchingPodServices, err := helper.GetPodServices(pl.serviceLister, pod) | |||
if err != nil { | |||
return nil, fmt.Errorf("listing pod services: %v", err.Error()) | |||
return nil, fmt.Errorf("listing pod services: %w", err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, don't call err.Error()
, because that's a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was too careless to notice the problem. Thank you very much. It has been revised.
6ca9bc4
to
f30518c
Compare
you have to fix the tests |
f30518c
to
a9f7568
Compare
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"k8s.io/api/core/v1" | ||
v1 "k8s.io/api/core/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this change is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -618,7 +619,7 @@ func TestPreFilterDisabled(t *testing.T) { | |||
} | |||
cycleState := framework.NewCycleState() | |||
gotStatus := p.Filter(context.Background(), cycleState, pod, nodeInfo) | |||
wantStatus := framework.AsStatus(fmt.Errorf(`error reading "PreFilterServiceAffinity" from cycleState: not found`)) | |||
wantStatus := framework.AsStatus(fmt.Errorf(`error reading "PreFilterServiceAffinity" from cycleState: %w`, errors.New("not found"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, export the error in framework/cycle_state.go
? That is the benefit of wrapping, that we can compare the exact error. Now, we shouldn't be using reflect, but that's a separate problem.
/retest |
/retest |
1 similar comment
/retest |
@@ -437,7 +438,7 @@ func TestPreFilterDisabled(t *testing.T) { | |||
} | |||
cycleState := framework.NewCycleState() | |||
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), cycleState, pod, nodeInfo) | |||
wantStatus := framework.NewStatus(framework.Error, `error reading "PreFilterNodeResourcesFit" from cycleState: not found`) | |||
wantStatus := framework.AsStatus(fmt.Errorf(`error reading "PreFilterNodeResourcesFit" from cycleState: %w`, errors.New(framework.NotFound))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make framework.NotFound
an error instead of a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alculquicondor, tanjing2020 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/priority backlog |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Which issue(s) this PR fixes:
Ref #94437
Special notes for your reviewer:
@alculquicondor
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: